package com.exploressquare.activity;

import android.content.Intent;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

import com.exploressquare.R;
import com.exploressquare.data.ParseFourSquareResponse;
import com.exploressquare.maps.Map_Adaptor;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;

public class MainActivity extends MapActivity {

	private Double distanceWeight;
	private Double popularityWeight;
	private Double reviewWeight;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		MapView mapView = (MapView) findViewById(R.id.mapview);
		mapView.setBuiltInZoomControls(true);

		// Log.d("loc",Double.toString(location.getLatitude()));

		ParseFourSquareResponse parseFourSquareResposne = new ParseFourSquareResponse();
		parseFourSquareResposne.getJSONStringAndParse(47.366667,8.55);

		Location location = new Location(LocationManager.GPS_PROVIDER);
		location.setLatitude(47.366667);
		location.setLongitude(8.55);

		final Map_Adaptor map_Adaptor = new Map_Adaptor(mapView);
		map_Adaptor.drawFourSquareOverlay(parseFourSquareResposne.getVd(), this
				.getResources().getDrawable(R.drawable.bar), mapView
				.getContext());

		map_Adaptor.setUserLatitude(location.getLatitude());
		map_Adaptor.setUserLongitude(location.getLongitude());
		map_Adaptor.drawUserLocation(
				this.getResources().getDrawable(R.drawable.urhere),
				mapView.getContext());

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.layout.menu, menu);
		return true;
	}

	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle item selection
		switch (item.getItemId()) {
		case R.id.searcharound:
			callSearchAround();
			return true;
		case R.id.settings:
			callSettings();
			return true;
		case R.id.searchmap:
			callSearchMap();
			return true;
		case R.id.searchlocality:
			callSearchLocality();
			return true;
		case R.id.searchmyplaces:
			callSearchMyPlaces();
			return true;
		case R.id.editmyplaces:
			callEditMyPlaces();
			return true;
		default:
			return super.onOptionsItemSelected(item);
		}
	}

	private void callSearchAround() {
		Intent goToNextActivity = new Intent(getApplicationContext(),
				SearchAroundMe.class);
		startActivity(goToNextActivity);
	}

	private void callSearchMap() {
		Intent goToNextActivity = new Intent(getApplicationContext(),
				SearchAroundMe.class);
		startActivity(goToNextActivity);
	}

	private void callSearchMyPlaces() {
		Intent goToNextActivity = new Intent(getApplicationContext(),
				SearchAroundMe.class);
		startActivity(goToNextActivity);
	}

	private void callSearchLocality() {
		Intent goToNextActivity = new Intent(getApplicationContext(),
				SearchAroundMe.class);
		startActivity(goToNextActivity);
	}

	private void callEditMyPlaces() {
		Intent goToNextActivity = new Intent(getApplicationContext(),
				SearchAroundMe.class);
		startActivity(goToNextActivity);
	}

	private void callSettings() {
		Intent goToNextActivity = new Intent(getApplicationContext(),
				SearchAroundMe.class);
		startActivity(goToNextActivity);
	}
	
	private void getWeights(){
		
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
		    distanceWeight  = extras.getDouble("distanceWeight");
		    popularityWeight  = extras.getDouble("popularityWeight");
		    reviewWeight = extras.getDouble("reviewWeight");
		}
	}

}
